package com.briup.jz.web.controller;

import com.briup.jz.bean.OrderLine;
import com.briup.jz.bean.extend.OrderExtend;
import com.briup.jz.service.IOrderService;
import com.briup.jz.service.IUserService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import com.briup.jz.vm.OrderVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: jz
 * @description: 订单管理
 * @author: 罗宇
 * @create: 2020-06-13 11:43
 **/
@RestController
@RequestMapping("/order")
@Api(description = "订单管理接口")

public class OrderController {


    @Autowired
    private IOrderService orderService;


    @PostMapping("commit")
    @ApiOperation("提交订单")
    public Message commit(@RequestBody OrderVM orderVM){
        orderService.commit(orderVM);
        return MessageUtil.success("提交成功");
    }

    @GetMapping("findAll")
    @ApiOperation("查询所有订单")
    public Message findAll(){
        return MessageUtil.success("success",orderService.findAll());
    }

    @GetMapping("findById")
    @ApiOperation("根据订单id查询订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别唯一编号", required = true, paramType = "query")
    })
    public Message findById(long id){
        return MessageUtil.success("success",orderService.findOrderDetailsById(id));
    }


    @GetMapping("findStatusByCustomerId")
    @ApiOperation("根据订单状态和客户id查询所有订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别唯一编号", required = true, paramType = "query"),
            @ApiImplicitParam(name = "string", value = "订单状态", required = true, paramType = "query")
    })
    public Message findStatusByCustomerId(String string,long id){
        return MessageUtil.success("success",orderService.findStatusByCustomerId(string,id));
    }
    @GetMapping("query")
    @ApiOperation("根据订单状态查询所有订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "订单状态", required = true, paramType = "query")
    })
    public Message findStatus(String status){
        return MessageUtil.success("success",orderService.findStatus(status));
    }

    @PostMapping("updateStatusById")
    @ApiOperation("根据订单id修改订单状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别唯一编号", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "订单状态", required = true, paramType = "query")
    })
    public Message updateStatusById(String status,long id){
        orderService.updateOrderStatusById(status,id);
        return MessageUtil.success("success");

    }
    @PostMapping("updateStatusBeConfirmed")
    @ApiOperation("根据id修改订单状态为待确认")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别唯一编号", required = true, paramType = "query")
    })
    public Message updateStatusBeConfirmed(long id){
        orderService.updateOrderStatusById("待确认",id);
        return MessageUtil.success("success");
    }
    @PostMapping("updateStatusBeEvaluated")
    @ApiOperation("根据id修改订单状态为待评价")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别唯一编号", required = true, paramType = "query")
    })
    public Message updateStatusBeEvaluated(long id){
        orderService.updateOrderStatusById("待评价",id);
        return MessageUtil.success("success");
    }
    @PostMapping("updateStatusFinished")
    @ApiOperation("根据id修改订单状态为已完成")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别唯一编号", required = true, paramType = "query")
    })
    public Message updateStatusFinished(long id){
        orderService.updateOrderStatusById("已完成",id);
        return MessageUtil.success("success");
    }
    @PostMapping("updateStatusPaid")
    @ApiOperation("根据id修改订单状态为已支付")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别唯一编号", required = true, paramType = "query")
    })
    public Message updateStatusPaid(long id){
        orderService.updateOrderStatusById("已支付",id);
        return MessageUtil.success("success");
    }

    @ApiOperation("派单")
    @ApiImplicitParams({
         @ApiImplicitParam(name = "orderId" ,value = "订单id" , required = true,paramType = "query") ,
         @ApiImplicitParam(name = "employeeId" ,value = "员工id" , required = true,paramType = "query")})
    @GetMapping("sendOrder")
    public Message updateOrderEmployeeById(long orderId,long employeeId) throws Exception {
//        orderService.sendOrder(orderId,employeeId);
        orderService.updateOrderEmployeeById(orderId, employeeId);
        orderService.updateOrderStatusById("待服务",orderId);
        return MessageUtil.success("success");
    }

    @ApiOperation("取消派单")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id" ,value = "订单id" , required = true,paramType = "query") ,})
    @PostMapping("cancelOrderEmployeeById")
        public Message cancelOrderEmployeeById(long id){
            orderService.updateOrderStatusById("待派单",id);
            return MessageUtil.success("success");
        }

   @GetMapping("findAllPaid")
   @ApiOperation("查询所有待派单订单")
   public Message findAllPaid(){
        return MessageUtil.success("success",orderService.findAllPaid());
    }
    @GetMapping("findPaidByCustomerId")
    @ApiOperation("根据客户id查询所有待派单订单")
    public Message  findPaidByCustomerId(long id){
        return MessageUtil.success("success",orderService.findPaidByCustomerId(id));
    }



    @GetMapping("findNotpayingByCustomerId")
    @ApiOperation("根据客户id查询所有待付款订单")
    public Message findStatusByCustomer(long id){
        return MessageUtil.success("success",orderService.findNotpayingByCustomerId(id));
    }
    @GetMapping("findAllNotpaying")
    @ApiOperation("查询所有待付款订单")
    public Message findAllNotpayingStatus(){
        return MessageUtil.success("success",orderService.findAllNotpaying());
    }





}